import { _decorator, Component, Label, Node } from 'cc';
import { UserInfo } from '../common/UserInfo';
import { EventManager } from '../event/EventManager';
import { Natural } from './Natural';
const { ccclass, property } = _decorator;

@ccclass('VillageResources')
export class VillageResources extends Component {
    private naturalList: Node

    private Timber: Label
    private quarry: Label
    private IronMine: Label
    private Food: Label


    start() {
        this.naturalList = this.node.getChildByPath('assetsBox/naturalList')
        this.Timber = this.node.getChildByPath('villageResources/oneTimeProduction/Timber/title1/t1').getComponent(Label)
        this.quarry = this.node.getChildByPath('villageResources/oneTimeProduction/quarry/title2/t2').getComponent(Label)
        this.IronMine = this.node.getChildByPath('villageResources/oneTimeProduction/IronMine/title3/t3').getComponent(Label)
        this.Food = this.node.getChildByPath('villageResources/oneTimeProduction/Food/title4/t4').getComponent(Label)



        EventManager.instance.on(EventManager.EventType.GetVillageDetail, this.updateData, this)
    }

    protected onDisable(): void {
        EventManager.instance.off(EventManager.EventType.GetVillageDetail, this.updateData, this)
    }

    updateData() {
        this.renderData()
        this.renderNatural()

    }

    renderData() {
        // 每小时资源产量
        let villageData = UserInfo.instance.villageData.res
        console.log(villageData, "villageDatavillageData")
        this.Timber.string = villageData.wood_output
        this.quarry.string = villageData.mud_output
        this.IronMine.string = villageData.iron_output
        this.Food.string = villageData.food_output
    }

    renderNatural() {
        // 资源田信息
        let data = UserInfo.instance.resource
        console.log(data, "UserInfo.instance.getVillageDetail")
        let children = this.naturalList.children

        for (let i = 0; i < children.length; i++) {
            children[i].getComponent(Natural).updateCover(data[i])
        }

    }
    update(deltaTime: number) {

    }
}


